-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Query Function As Query_string Function #143
Added Query Function As Query_string Function #143
Conversation
Codecov Report
@@ Coverage Diff @@
## integ-add-query-function #143 +/- ##
==============================================================
+ Coverage 94.95% 95.23% +0.28%
- Complexity 3190 3395 +205
==============================================================
Files 316 330 +14
Lines 8646 9302 +656
Branches 637 691 +54
==============================================================
+ Hits 8210 8859 +649
- Misses 382 386 +4
- Partials 54 57 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job guys! Thanks for the work. Just a couple of comments
@@ -38,7 +38,7 @@ public void queryTest() throws IOException { | |||
"select address from %s where query('address:880 Holmes Lane') limit 3", | |||
TestsConstants.TEST_INDEX_ACCOUNT)); | |||
Assert.assertThat(result, | |||
containsString("query_string\":{\"query\":\"address:880 Holmes Lane")); | |||
containsString("query_string\\\":{\\\"query\\\":\\\"address:880 Holmes Lane")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wasn't working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were some issues with escaped characters causing it to fail.
@Test | ||
public void all_fields_test() throws IOException { | ||
String query = "SELECT * FROM " | ||
+ TEST_INDEX_BEER + " WHERE query('*:taste')"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the wildcard syntax doesn't work? Or does it work with just *
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too... I thought we determined that they didn't work when we had our 1:1. I played around with it trying different combinations...
The following all seem to work when passed in as the query for query_string:
"* : taste"
"* : ?aste"
"Tags : *aste"
"Tags : Ta?te"
"Tags : Ta*te"
I tried these according to this documentation for Lucene, but it doesn't seem to follow it exactly since it also allows *
and ?
to be the first character of a search. Should we add tests for all of these cases as well? I can't find a specific Doc to reference for what should/shouldn't be supported in the query so I'm not really sure what other behaviour we should be testing for that we might be missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Unit Tests in f2d77c6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more asking about the field name (*
or Tags
). It seems like those two cases are fine, but T?g*
is not?
Honestly, the checks are handled by OpenSearch not us... so what additional tests are going to do is test another system. We can consider covering some of the general cases, but we do not need to be exhaustive here.
.../java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQuery.java
Outdated
Show resolved
Hide resolved
...arch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java
Show resolved
Hide resolved
...arch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/QueryTest.java
Outdated
Show resolved
Hide resolved
sql/src/test/java/org/opensearch/sql/sql/parser/AstExpressionBuilderTest.java
Outdated
Show resolved
Hide resolved
...a/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQueryTest.java
Show resolved
Hide resolved
.../java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQuery.java
Outdated
Show resolved
Hide resolved
.../java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQuery.java
Outdated
Show resolved
Hide resolved
...in/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryQuery.java
Show resolved
Hide resolved
.../java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/NoFieldQuery.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/opensearch/sql/sql/parser/AstExpressionBuilder.java
Outdated
Show resolved
Hide resolved
Hint: |
...in/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryQuery.java
Outdated
Show resolved
Hide resolved
827a0cf
to
89b3e1a
Compare
d49c0d1
to
9d14975
Compare
@@ -81,4 +102,5 @@ public QueryBuilder build(FunctionExpression func) { | |||
protected interface QueryBuilderStep<T extends QueryBuilder> extends | |||
BiFunction<T, ExprValue, T> { | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting change not needed, and really should only be included in a review when appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7add05f
@@ -523,6 +523,7 @@ public void relevanceSimple_query_string() { | |||
+ "analyzer='keyword', operator='AND')")); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7add05f
String.format("Parameter '%s' can only be specified once.", k)); | ||
} | ||
}); | ||
.forEach((k, v) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting change not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced by accident when I was trying to fix checkstyle issues. Fixed in 7add05f
queryBuildActions | ||
.get(argNormalized))) | ||
.apply(queryBuilder, arg.getValue().valueOf(null)); | ||
queryBuildActions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting change not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced by accident when I was trying to fix checkstyle issues. Fixed in 7add05f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than some unnecessary formatting changes.
@Test | ||
public void all_fields_test() throws IOException { | ||
String query = "SELECT * FROM " | ||
+ TEST_INDEX_BEER + " WHERE query('*:taste')"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more asking about the field name (*
or Tags
). It seems like those two cases are fine, but T?g*
is not?
Honestly, the checks are handled by OpenSearch not us... so what additional tests are going to do is test another system. We can consider covering some of the general cases, but we do not need to be exhaustive here.
docs/user/dql/functions.rst
Outdated
@@ -2963,7 +2963,7 @@ Description | |||
|
|||
``query_string([field_expression+], query_expression[, option=<option_value>]*)`` | |||
|
|||
The query_string function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields. | |||
The query_string function maps to the query_string query used in search engine (also used by `query`_), to return the documents that match a provided text, number, date or boolean value with a given field or fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove, this is confusing and covered below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7add05f
docs/user/dql/functions.rst
Outdated
|
||
``query("query_expression" [, option=<option_value>]*)`` | ||
|
||
This is an alternative syntax to the `query_string`_ function. The query function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an alternative syntax to the `query_string`_ function. The query function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields. | |
The `query` function is an alternative syntax to the `query_string` function. It maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given query expression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to remove the links entirely? They were originally added to address this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can apply the change and restore the link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the language to match the suggestion, but kept the link to query_string
. Please let me know if you are ok with this. Done in 7add05f
void query_expression() { | ||
assertAnalyzeEqual( | ||
dsl.query( | ||
dsl.namedArgument("query", DSL.literal("query_value"))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: change "query_value" to "sample query" or "field:query" or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ef2f4c9
Signed-off-by: GabeFernandez310 <[email protected]>
ef2f4c9
to
52ea1e5
Compare
Description
Added query function to SQL plugin. Achieved by routing function calls from the SQL plugin to the query_string function which currently exists in OpenSearch.
Currently blocked by opensearch-project#839. PR to upstream will be made once PR opensearch-project#839 is merged.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.